using System.Reflection;
using Crux.Core.Data;

namespace Crux.Core.NHibernate;
/// <summary>
/// SoftDeleteExtensions
/// </summary>
public static class SoftDeleteExtensions
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public static bool IsSoftDelete(this Type type)
    {
        var implementedInterfaces = type.GetTypeInfo().GetInterfaces();

        foreach (var _interfaceType in implementedInterfaces)
        {
            if (typeof(ISoftDelete).IsGenericType != _interfaceType.IsGenericType)
            {
                continue;
            }

            if (_interfaceType.IsGenericType)
            {
                var genericType = _interfaceType.GetGenericTypeDefinition();
                if (genericType == typeof(ISoftDelete))
                {
                    return true;
                }
            }
            else
            {
                if (_interfaceType == typeof(ISoftDelete))
                {
                    return true;
                }
            }
        }
        return false;
    }

}